var LLParser = require('./LLParser');
var GlobalErrorListener = require('./GlobalErrorListener');
var dataUtils = require('./dataUtils');
var Event = require('./Event');
var dataPath = require('./dataPath');
var Behavior = require('./Behavior');
var Element = require('./Element');
var Component = require('./Component');
var TextNode = require('./TextNode');
var NativeNode = require('./NativeNode');
var VirtualNode = require('./VirtualNode');
var ShadowRoot = require('./ShadowRoot');
var DataGroup = require('./DataGroup');
var Observer = require('./Observer');
var ElementIterator = require('./ElementIterator');
var FakeDomElement = require('./FakeDomElement');
var globalOptions = require('./globalOptions');
var globalState = require('./globalState');
var FreeTmpl = require('./FreeTmpl');
exports.FreeTmpl = FreeTmpl;
exports.precompileTemplate = FreeTmpl.precompiler ? FreeTmpl.precompiler.compile : null;
exports.precompiler = FreeTmpl.precompiler ? FreeTmpl.precompiler : null;
exports.HtmlLLParser = FreeTmpl.htmlParser ? FreeTmpl.htmlParser : null;
exports.LLParser = LLParser;
exports.dataPath = dataPath;
exports.dataUtils = dataUtils;
exports.Event = Event;
exports.Element = Element;
exports.TextNode = TextNode;
exports.NativeNode = NativeNode;
exports.VirtualNode = VirtualNode;
exports.ShadowRoot = ShadowRoot;
exports.Behavior = Behavior;
exports.Component = Component;
exports.Observer = Observer;
exports.DataGroup = DataGroup;
exports.ElementIterator = ElementIterator;
exports.FakeDomElement = FakeDomElement;
exports.registerBehavior = Behavior.create;
exports.registerElement = Component.register;
exports.createElement = Component.create;
exports.createTextNode = TextNode.create;
exports.createVirtualNode = VirtualNode.create;
exports.appendChild = Element.appendChild;
exports.insertBefore = Element.insertBefore;
exports.removeChild = Element.removeChild;
exports.replaceChild = Element.replaceChild;
exports.addListenerToElement = Event.addListenerToElement;
exports.removeListenerFromElement = Event.removeListenerFromElement;
exports.triggerEvent = Event.triggerEvent;
exports.safeCallback = GlobalErrorListener.safeCallback;
exports.addGlobalErrorListener = GlobalErrorListener.addGlobalErrorListener;
exports.removeGlobalErrorListener = GlobalErrorListener.removeGlobalErrorListener;
exports.addGlobalWarningListener = GlobalErrorListener.addGlobalWarningListener;
exports.removeGlobalWarningListener = GlobalErrorListener.removeGlobalWarningListener;
exports.globalOptions = globalOptions;
exports.globalState = globalState;
Component._setDefaultTemplateEngine(FreeTmpl);
(exports.updateDefaultComponent = function () {
    delete Component._list[''];
    Component.register({
        is: '',
        options: {
            writeOnly: true,
            allowInWriteOnly: true,
            lazyRegistration: false,
            classPrefix: '',
            addGlobalClass: false,
            templateEngine: null,
            renderingMode: 'full',
            multipleSlots: false,
            reflectToAttributes: false
        }
    });
})();
var b = function (e) {
    var t = '';
    if (e instanceof exparser.Element) {
        e.id && (t += ' id="' + e.id + '"');
        e.slot && (t += ' slot="' + e.slot + '"');
        e.__slotName && (t += ' name="' + e.__slotName + '"');
        e.classList && (t += ' class="' + e.class + '"');
        e.$$ && e.$$.getAttribute('style') && (t += ' style="' + e.$$.getAttribute('style') + '"');
    };
    if (e instanceof exparser.VirtualNode)
        return t;
    if (e instanceof exparser.Component) {
        Component.listPublicProperties(e).forEach(function (i) {
            t += ' ' + i + '=' + JSON.stringify(e[i]);
        });
        return t;
    }
    var i = e.attributes;
    for (var n = 0; n < i.length; n++)
        t += ' ' + i[n].name + '="' + i[n].value + '"';
    return t;
};
var C = exports.dumpElementToString = function (e, t, i) {
    var n = null;
    globalOptions.hasDOMBackend && (n = window);
    var a = 0;
    var r = '';
    for (a = i = i || 0; a; a--)
        r += '  ';
    var o = '';
    if (e instanceof exparser.Element) {
        o += r + '<' + (e.$$ ? e.$$.tagName.toLowerCase() + ':' : '') + e.is + b(e) + '>';
        if (e instanceof exparser.VirtualNode) {
            o += ' [Exp-Virtual]';
        } else {
            e instanceof exparser.NativeNode ? o += ' [Exp-Native]' : o += ' [Exp-Component]';
        }
        o += '\n' + C(t ? e.__wxSlotChildren : e.childNodes, t, i + 1);
    } else if (e instanceof exparser.TextNode)
        o += r + e.textContent + ' [Exp-Text]\n';
    else if (n && n.HTMLElement && e instanceof n.HTMLElement)
        o += r + '<' + e.tagName.toLowerCase() + b(e) + '> [DOM-Element]', o += '\n' + C(t && e.__wxSlotChildren || e.childNodes, t, i + 1);
    else if (n && n.Text && e instanceof n.Text)
        o += r + e.textContent + ' [DOM-Text]\n';
    else if (undefined !== e.length)
        for (a = 0; a < e.length; a++)
            o += C(e[a], t, i);
    else
        o = r + '[unknown node]\n';
    return o;
};
exports.dumpElement = function (e, t) {
    console.log(C(e, t));
};
